<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page language="java" pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html:html>
<head>
	<title><bean:message key="application.title" /></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="./extjs/resources/css/ext-all.css">
    <script type="text/javascript" src="./extjs/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="./extjs/ext-all.js"></script>
    <script type="text/javascript">
		Ext.BLANK_IMAGE_URL = "./extjs/resources/images/default/s.gif";
		Ext.namespace("shapeline");
		shapeline.app = function() {
		    var loginButton;
		    var loginButtonHandler = function(button, event) {
		    	document.getElementById("message").innerHTML = "";
		    	Ext.Ajax.request({
	        		url: "login.shtml",
	        		params: {
	        			name: document.getElementById('name').value,
	        			password: document.getElementById('password').value
	        		},
	        		success: function(response, options) {
	        			var message = Ext.util.JSON.decode(response.responseText);
	        			if (message.success) {
		        			location.href = "home.shtml";
	        			}
	        			else {
			        		document.getElementById("message").innerHTML = message.message;
	        			}
	        		},
	        		failure: function(respinse, options) {
		        		document.getElementById("message").innerHTML = response.responseText;
	        		}
	        	});
		    }
		    return {
		        btnText: '<bean:message key="login.button" />',
		        init: function() {
		    		loginButton = new Ext.Button({
		                renderTo: "btn-login",
		                text: this.btnText,
		                handler: loginButtonHandler,
		                scope: this
		            });
		        }
		    };
		}();
    </script>
	<script type="text/javascript">
		Ext.onReady(shapeline.app.init, shapeline.app);
	</script>
</head>
<body>
	<br/><br/><br/><br/><br/>
	<div align="center">
		<form id="loginForm" action="login.shtml" method="post">
			<div id="loginNameDiv"><bean:message key="login.name" /> <input id="name" name="name" type="text" size="10"/></div>
			<div id="passwordDiv"><bean:message key="login.password" /> <input id="password" name="password" type="password" size="10"/></div>
			<div id="btn-login"></div>
			<div id="message"></div>
		</form>
	</div>
</body>
</html:html>
